﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyPSDALayer;

namespace MyPS.Areas.Manage.Controllers
{
    [Authorize]
    public class CaseTypesController : Controller
    {
        private MyPSEntities db = new MyPSEntities();

        //
        // GET: /Manage/CaseTypes/

        public ActionResult Index()
        {
            return View(db.CaseTypes.ToList());
        } 
     
        //
        // GET: /Manage/CaseTypes/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Manage/CaseTypes/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(CaseType casetype)
        {
            if (ModelState.IsValid)
            {
                casetype.CreateBy = HttpContext.User.Identity.Name;
                casetype.CreateDate = DateTime.Now;
                casetype.ModifyBy = HttpContext.User.Identity.Name;
                casetype.ModifyDate = DateTime.Now;
                casetype.IsDel = "N";
                db.CaseTypes.Add(casetype);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(casetype);
        }

        //
        // GET: /Manage/CaseTypes/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CaseType casetype = db.CaseTypes.Find(id);
            if (casetype == null)
            {
                return HttpNotFound();
            }
            return View(casetype);
        }

        //
        // POST: /Manage/CaseTypes/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(CaseType casetype)
        {
            if (ModelState.IsValid)
            {
                casetype.ModifyBy = HttpContext.User.Identity.Name;
                casetype.ModifyDate = DateTime.Now;
                casetype.IsDel = "N";
                db.Entry(casetype).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(casetype);
        }

        //
        // GET: /Manage/CaseTypes/Delete/5

        public ActionResult Delete(int id = 0)
        {
            CaseType casetype = db.CaseTypes.Find(id);
            if (casetype == null)
            {
                return HttpNotFound();
            }
            return View(casetype);
        }

        //
        // POST: /Manage/CaseTypes/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            CaseType casetype = db.CaseTypes.Find(id);
            db.CaseTypes.Remove(casetype);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}